package com.liaoban.app.ui.mine;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.liaoban.app.R;
import com.liaoban.app.api.type.request.FeedBackRequest;
import com.liaoban.app.biz.CommonBiz;
import com.liaoban.app.helper.ToastHelper;
import com.liaoban.app.ui.base.BaseToolbarActivity;
import com.liaoban.app.widget.MyTextWatcher;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by ybc on 2018/7/10 0010.
 * 意见反馈
 */
public class FeedBackActivity extends BaseToolbarActivity {
    @BindView(R.id.iv_right)
    ImageView ivRight;
    @BindView(R.id.et_content)
    EditText etContent;
    @BindView(R.id.tv_count)
    TextView tvCount;

    @Override
    protected String getNewTitle() {
        return getString(R.string.feed_back);
    }

    @Override
    protected int getLayoutResID() {
        return R.layout.activity_feed_back;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        ivRight.setImageResource(R.mipmap.ic_confirm);
        ivRight.setVisibility(View.VISIBLE);
        MyTextWatcher myTextWatcher = new MyTextWatcher(() -> {
            int count = etContent.getText().toString().trim().length();
            tvCount.setText(count + "/200");
        });
        etContent.addTextChangedListener(myTextWatcher);
    }

    @OnClick(R.id.iv_right)
    public void right() {
        String content = etContent.getText().toString().trim();
        if (TextUtils.isEmpty(content)) {
            ToastHelper.show(this, "提交内容不能为空");
            return;
        }
        showRunningDialog(R.string.committing);
        FeedBackRequest feedBackRequest = new FeedBackRequest();
        feedBackRequest.setContent(content);
        startTask(CommonBiz.getInstance().feedBack(feedBackRequest), baseResponse -> {
            ToastHelper.show(FeedBackActivity.this, baseResponse.msg);
            finish();
        });
    }

}
